#include "LPC17xx.h"
#include "wdt.h"
#include "interrupt.h"


/**
 * WDT interrupt service routine
 *
 * @param  none
 * @return none
 *
 * @brief  handle wdt interrupt
 *
 *
 */
void wdt_isr(void)
{
  WDT -> WDMOD &= ~WDTOF;
  while(1);

}

/**
 * initialize watchdog timer service routine
 *
 * @param  none
 * @return none
 *
 * @brief  init wdt
 *
 *
 */
void wdt_init( void )
{

  /* set timeout value */
  WDT -> WDTC = WDT_FEED_VALUE;

  /* enable wdt and reset controller on timeout */
  WDT -> WDMOD = WDRESET|WDEN;

  /* start feed sequence */
  WDT -> WDFEED = WDT_VALUE_1;
  WDT -> WDFEED = WDT_VALUE_2;

  /* set interrupt priority */
  NVIC_SetPriority(WDT_IRQn, WDT_NVIC_PRIO);

  /* enable interrupts in NVIC */
  NVIC_EnableIRQ(WDT_IRQn);

  return;
}


/**
 * WDT reset
 *
 * @param  none
 * @return none
 *
 * @brief  reset watchdog timer
 *
 *
 */
void wdt_reset( void )
{

  /* feed watchdog timer */
  WDT -> WDFEED = WDT_VALUE_1;
  WDT -> WDFEED = WDT_VALUE_2;
  return;

}
